package com.SmsModule.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import util.TotalClass;
import util.UtilDAO;

import com.SmsModule.bean.TbSmsReceive;
import com.SmsModule.bean.TbSmsSc;
import com.SmsModule.bean.TbSmsSend;
import com.dianbo.bean.DianboType;

/**
 * 短信发送模块操作DAO
 * jhc
 * 2011-1-27下午01:51:54
 */
public class TbSmsSendDAO {
	private String sql = "";
	private DianboType dianboType=null;
	private List<DianboType> dianboTypeList = null;
	List<TbSmsSend> smsSendList = null;
	List<TbSmsReceive> smsRecList = null;
	List<TbSmsSc> tbSmsScList = null;
	private ResultSet rs = null;
	private Statement st = null;
	/**
	 * 
	 *@author qingyu zhang
	 *@function:批量导入短信
	 * @param smsList
	 * @return
	 *2011-4-10
	 *上午10:31:23
	 *zzClub
	 *com.SmsModule.dao
	 *boolean
	 */
	public boolean addSmsList(List<TbSmsSend> smsList){
		boolean bo = false;
		try{
			st = new TotalClass().getStatement();
			if(smsList!=null&&smsList.size()>0){
				for(TbSmsSend smsSend:smsList){
					String hql = "insert into tb_sms_send (userId,smsContent,smsSendState,sendTime,destAdd,isSendTime,createTime,seriseId) " +
							"values("+smsSend.getUserId()+",'"+smsSend.getSmsContent()+"',"+smsSend.getSmsSendState()+",'"+smsSend.getSendTime()
							+"','"+smsSend.getDestAdd()+"',"+smsSend.getIsSendTime()+",'"+smsSend.getCreateTime()+"','"+smsSend.getSeriseId()+"')";
					
					st.addBatch(hql);
				}
				st.executeBatch();
			}
			bo = true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return bo;
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:发送答题方法
	 * @param smsList
	 * @return
	 *2011-4-13
	 *下午02:20:59
	 *zzClub
	 *com.SmsModule.dao
	 *boolean
	 */
	public boolean addSmsListDati(List<TbSmsSend> smsList){
		boolean bo = false;
		try{
			st = new TotalClass().getStatement();
			if(smsList!=null&&smsList.size()>0){
				for(TbSmsSend smsSend:smsList){
					String hql = "insert into tb_sms_send (userId,smsContent,smsSendState,sendTime,destAdd,isSendTime,createTime,seriseId) " +
					"values("+smsSend.getUserId()+",'"+smsSend.getSmsContent()+"',"+smsSend.getSmsSendState()+",'"+smsSend.getSendTime()
					+"','"+smsSend.getDestAdd()+"',"+smsSend.getIsSendTime()+",'"+smsSend.getCreateTime()+"','"+smsSend.getSeriseId()+"')";
					System.out.println("插入tb_sms_send=="+hql);
					st.addBatch(hql);
				}
				st.executeBatch();
			}
			bo = true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return bo;
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:
	 * @param table
	 * @param order
	 * @param condition
	 * @return
	 *2011-4-11
	 *上午09:13:59
	 *zzClub
	 *com.SmsModule.dao
	 *List<TbSmsSend>
	 */
	public List<TbSmsSend> getSmsList(String table,String order,String condition){
		sql= UtilDAO.getList(table, order, condition);
		rs = new TotalClass().getResult(sql);
		try {
			while(rs.next()){
				if(smsSendList==null){
					smsSendList =new  ArrayList<TbSmsSend>();
				}
				smsSendList.add(this.getSmsSend(rs));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return smsSendList;
	}
	public TbSmsSend getSmsSend(ResultSet rs){
		TbSmsSend smsSend = new TbSmsSend();
		try {
				smsSend.setCreateTime(rs.getString("createTime"));
				smsSend.setDestAdd(rs.getString("destAdd"));
				smsSend.setIsSendTime(rs.getInt("isSendTime"));
				smsSend.setSendTime(rs.getString("sendTime"));
				smsSend.setSmsContent(rs.getString("smsContent"));
				smsSend.setSmsId(rs.getInt("smsId"));
				smsSend.setSmsSendState(rs.getInt("smsSendState"));
				smsSend.setUserId(rs.getInt("userId"));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return smsSend;
	}
	public List<TbSmsReceive> getSmsRecList(String table,String order,String condition){
		sql= UtilDAO.getList(table, order, condition);
		System.out.println("语句=="+sql);
		rs = new TotalClass().getResult(sql);
		try {
			while(rs.next()){
				if(smsRecList==null){
					smsRecList =new  ArrayList<TbSmsReceive>();
				}
				smsRecList.add(this.getSmsRecSend(rs));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return smsRecList;
	}
	public TbSmsReceive getSmsRecSend(ResultSet rs){
		TbSmsReceive smsRec = new TbSmsReceive();
		try {
			smsRec.setOrgNum(rs.getString("orgNum"));
			smsRec.setReceiveContent(rs.getString("receiveContent"));
			smsRec.setReceiveId(rs.getInt("receiveId"));
			smsRec.setReceiveTime(rs.getString("receiveTime"));
			smsRec.setReceiveType(rs.getInt("receiveType"));
			smsRec.setSendPhone(rs.getString("sendPhone"));
			smsRec.setState(rs.getInt("state"));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return smsRec;
	}
	public List<TbSmsSc> getSmsSc(String table,String order,String condition){
		sql= UtilDAO.getList(table, order, condition);
		System.out.println("语句=="+sql);
		rs = new TotalClass().getResult(sql);
		try {
			while(rs.next()){
				if(tbSmsScList==null){
					tbSmsScList = new ArrayList<TbSmsSc>();
				}
				tbSmsScList.add(this.getSmsSc(rs));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tbSmsScList;
	}
	public TbSmsSc getSmsSc(ResultSet rs){
		TbSmsSc tbSmsSc = new TbSmsSc();
		try {
			tbSmsSc.setCreateTime(rs.getString("createTime"));
			tbSmsSc.setDestAdd(rs.getString("destAdd"));
			tbSmsSc.setSendPhone(rs.getString("sendPhone"));
			tbSmsSc.setSmscontent(rs.getString("smscontent"));
			tbSmsSc.setSmsId(rs.getInt("smsId"));
			tbSmsSc.setSmsType(rs.getInt("smsType"));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tbSmsSc;
	}
	/**
	 * 短信重发功能
	 *@author qingyu zhang
	 *@function:
	 * @param str
	 *2011-5-5
	 *下午05:29:18
	 *zzClub
	 *com.SmsModule.dao
	 *void
	 */
	public boolean  updateSmsSend(String str){
		boolean bo = false;
		st = new TotalClass().getStatement();
		try {
			st.execute(str);
			bo = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bo;
	}
}
